Skip to content

feat(credentials): add opt-in model-scoped credential cooldown - #26

Merged
ALikesToCode merged 1 commit into
integrate/gateway-waves-1-2from
feat/model-cooldown
Oct 9, 2026
Merged

ALikesToCode merged 1 commit into
integrate/gateway-waves-1-2from
feat/model-cooldown

Conversation

@ALikesToCode

Copy link
Copy Markdown
Owner

Summary

Adds model-scoped credential cooldown behind MODEL_COOLDOWN_ENABLED, which defaults to false. While the flag is off, key selection and cooldowns are unchanged.

  • With the flag on, a 429 or quota exhaustion cools only that credential for the affected model, or for an explicitly configured shared quota bucket. Other models can still use the key.
    • Only a genuine credential-wide authentication rejection cools the key for every model.
    • A success clears only that model's entry.
  • Outcomes come from the upstream outcome classifier, not from the raw status alone. MODEL_COOLDOWN_MAX_SECONDS (default 3600) caps any cooldown.
  • If every eligible key is cooling for the model, the request gets a real 429 with a bounded Retry-After instead of being dispatched anyway.
  • Calls that do not pass a model keep the existing provider-wide cooldowns exactly, even with the flag on. A key rested by such a call is also skipped by model-scoped selection.
  • State is process-local and bounded to 10,000 entries. Credentials are identified by an HMAC digest and are never stored or logged.

Details are in docs/model-cooldown.md.

Integration

CredentialPool and NanoGPTKeyPool accept the model, quota bucket and outcome. The request paths that call them (auth_service, intelligence_transport, proxy_service, routes/proxy.py and routes/provider_credentials.py) start passing the model in the Wave 3 integration PR. Until then, every path keeps the provider-wide behaviour.

Shared registrations

  • Added MODEL_COOLDOWN_ENABLED and MODEL_COOLDOWN_MAX_SECONDS to the Container env keys.

Tests

  • tests/test_model_cooldown.py: new. It covers the flag-on calls with no model, which keep the 429 and 401 cooldowns.
  • Full Python suite: 3,241 passed. ruff, mypy and bandit are clean.
  • npm run test:worker: 1,227 passed. cf:migrations:check, test:deploy, free routes, client headers and the wrangler deploy --dry-run bundle all pass.
  • tests/test_frontend_build.mjs fails locally because @tailwindcss/cli is not installed. It fails the same way on main.

This is part of Wave 3. It is based on the Wave 2 integration branch (#25), and the Wave 3 integration PR adds the README line.

MODEL_COOLDOWN_ENABLED (default off) scopes a throttled or exhausted credential to the affected model or an explicitly configured quota bucket, so other models keep using the key. Only a genuine credential-wide authentication rejection cools every model. When every eligible key is cooling, the request gets a real 429 with a bounded Retry-After. Calls that pass no model keep the existing provider-wide cooldowns, even with the flag on.
@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b16c6821-2eef-4478-951c-9d8bb2772487

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T21:43:55.505689Z 08a4094 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
multillm-proxy 08a4094 Oct 08 2026, 09:42 PM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08a4094e66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +79 to +80
config = settings()
if config.enabled and (model or quota_bucket):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass request scope into production pool calls

With MODEL_COOLDOWN_ENABLED=true, this branch still never executes for repository production traffic because all callers retain the new arguments' None defaults: AuthService.get_api_key calls CredentialPool.select(provider), ProxyService.make_request calls record_headers without scope, and the NanoGPT proxy, unified, and intelligence paths likewise omit model from selection and recording. Consequently a production 429 continues using the legacy provider-wide cooldown rather than the advertised model-scoped state; pass the resolved upstream model or configured quota bucket through both sides of each request.

Useful? React with 👍 / 👎.

Comment on lines +79 to +83
def cooldown_error_response(error: ModelCooldownExhausted | ModelCooldownCapacity):
"""Emit the cooldown status and bounded Retry-After advice."""
response = jsonify(error.to_dict())
response.status_code = error.status_code
response.headers["Retry-After"] = str(error.retry_after)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Register the cooldown error adapter

When a scoped pool raises ModelCooldownExhausted or ModelCooldownCapacity, this response builder is never registered by the application: app.py only invokes init_error_handlers, whose generic APIError handler omits Retry-After. Thus clients receive the status but lose the only bounded wait guidance and may retry immediately; register this adapter for both exception classes during application initialization.

Useful? React with 👍 / 👎.

@ALikesToCode
ALikesToCode merged commit daa32fa into integrate/gateway-waves-1-2 Oct 9, 2026
5 of 7 checks passed
@ALikesToCode
ALikesToCode deleted the feat/model-cooldown branch October 26, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant